package crawler.web.beans;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * @author waynechen Mar 20, 2012 10:15:11 AM
 */
public class TagData implements Serializable {
	public String format(TagData td) {
		StringBuilder sb = new StringBuilder();
		format(td, sb, "");
		return sb.toString();
	}

	private void format(TagData td, StringBuilder sb, String prefix) {
		sb.append(prefix).append("{").append("\n");
		sb.append(prefix).append("  attr = ").append(td.getTagAttributes().toString()).append("\n");
		sb.append(prefix).append("  text = ").append(td.getTagText().toString().replace("\n", "###")).append("\n");
		sb.append(prefix).append("  subN = ").append("\n");
		for (int i = 0; i < td.getSubTagDataList().size(); i++) {
			format(td.getSubTagDataList().get(i), sb, prefix + "︿");
		}
		sb.append(prefix).append("}").append("\n");
	}

	private static final long serialVersionUID = 4943377728449919906L;
	private StringBuilder tagAttributes = new StringBuilder();
	private StringBuilder tagText = new StringBuilder();
	private List<TagData> subTagDataList = new ArrayList<TagData>();

	@Override
	public String toString() {
		return format(this);
	}

	public StringBuilder getTagAttributes() {
		return tagAttributes;
	}

	public void setTagAttributes(StringBuilder tagAttribute) {
		this.tagAttributes = tagAttribute;
	}

	public StringBuilder getTagText() {
		return tagText;
	}

	public void setTagText(StringBuilder tagText) {
		this.tagText = tagText;
	}

	public List<TagData> getSubTagDataList() {
		return subTagDataList;
	}

	public void setSubTagDataList(List<TagData> subTagDataList) {
		this.subTagDataList = subTagDataList;
	}

}
